package com.ohos.carbon.slice;

import com.ohos.carbon.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.ElementScatter;

import static com.ohos.carbon.ResourceTable.*;

public class CodeSlice extends AbilitySlice {
    private Text codeText, textTitle;
    private Image checkbox, back_button, debug;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(Layout_ability_xml_code);
        initView();
    }

    public void initView() {
        back_button = (Image) findComponentById(Id_back_button);
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_uparrow));
        back_button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                onBackPressed();
            }
        });

        debug = (Image) findComponentById(Id_image1);
        debug.setVisibility(Component.HIDE);
        checkbox = (Image) findComponentById(Id_image2);
        checkbox.setVisibility(Component.HIDE);
        textTitle = (Text) findComponentById(Id_title_text);
        textTitle.setText("XML Code");

        codeText = (Text) findComponentById(ResourceTable.Id_code_text);
        codeText.setText(code);
    }

    String code = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
            "<DirectionalLayout\n" +
            "    xmlns:ohos=\"http://schemas.huawei.com/res/ohos\"\n" +
            "    ohos:height=\"match_parent\"\n" +
            "    ohos:width=\"match_parent\"\n" +
            "    ohos:orientation=\"vertical\">\n" +
            "\n" +
            "    <DirectionalLayout\n" +
            "        ohos:height=\"match_content\"\n" +
            "        ohos:width=\"match_parent\"\n" +
            "        ohos:orientation=\"horizontal\">\n" +
            "\n" +
            "        <include\n" +
            "            ohos:height=\"60vp\"\n" +
            "            ohos:width=\"match_parent\"\n" +
            "            layout=\"$layout:back_titlebar\"/>\n" +
            "    </DirectionalLayout>\n" +
            "\n" +
            "    <DirectionalLayout\n" +
            "        ohos:height=\"match_content\"\n" +
            "        ohos:width=\"match_parent\"\n" +
            "        ohos:left_margin=\"15vp\"\n" +
            "        ohos:orientation=\"horizontal\"\n" +
            "        ohos:right_margin=\"15vp\"\n" +
            "        ohos:top_margin=\"10vp\">\n" +
            "\n" +
            "        <Text\n" +
            "            ohos:height=\"match_content\"\n" +
            "            ohos:width=\"match_parent\"\n" +
            "            ohos:multiple_lines=\"true\"\n" +
            "            ohos:text=\"This is the code used to display the sample. XML and Java/Kotlin, when neccessary. Carbon-specific stuff in blue.\"\n" +
            "            ohos:text_color=\"$color:gray\"\n" +
            "            ohos:text_size=\"14vp\"\n" +
            "            ohos:weight=\"10\"/>\n" +
            "\n" +
            "        <ScrollView\n" +
            "            ohos:height=\"match_parent\"\n" +
            "            ohos:width=\"match_content\">\n" +
            "\n" +
            "            <Text\n" +
            "                ohos:id=\"$+id:code_text\"\n" +
            "                ohos:height=\"match_parent\"\n" +
            "                ohos:width=\"match_parent\"\n" +
            "                ohos:padding=\"16vp\"/>\n" +
            "        </ScrollView>\n" +
            "    </DirectionalLayout>\n" +
            "\n" +
            "</DirectionalLayout>";

}
